Dart.PowerTCP.SslSockets Namespace > Udp Class > BeginSend Method : BeginSend(Byte[],Int32,Int32,SocketFlags,IPEndPoint,Object) Method |
Asynchronously send a datagram to the specified IPEndPoint, specifying a buffer, offset, count and SocketFlags value.
[Visual Basic]
<DescriptionAttribute("Send data from your buffer asynchronously. The EndSend event is raised when completed.")>
Overloads Public Function BeginSend( _
ByVal buffer() As Byte, _
ByVal offset As Integer, _
ByVal count As Integer, _
ByVal socketFlags As SocketFlags, _
ByVal host As IPEndPoint, _
ByVal state As Object _
) As IAsyncResult
[C#]
[DescriptionAttribute("Send data from your buffer asynchronously. The EndSend event is raised when completed.")]
public IAsyncResult BeginSend(
byte[] buffer,
int offset,
int count,
SocketFlags socketFlags,
IPEndPoint host,
object state
);
[C++]
[DescriptionAttribute("Send data from your buffer asynchronously. The EndSend event is raised when completed.")]
public: IAsyncResult* BeginSend(
byte[]* buffer,
int offset,
int count,
SocketFlags socketFlags,
IPEndPoint* host,
Object* state
)
[C++/CLI]
[DescriptionAttribute("Send data from your buffer asynchronously. The EndSend event is raised when completed.")]
public:
IAsyncResult^ BeginSend(
bytearray<buffer>^ buffer,
int offset,
int count,
SocketFlags socketFlags,
IPEndPoint^ host,
Object^ state
)
An IAsyncResult that represents the asynchronous send, which could still be pending.
Exception | Description |
---|---|
ArgumentNullException | buffer is null. |
SocketException | The remote address is unknown, invalid, or unable to be resolved. |
ArgumentOutOfRangeException | The remote port is out of the range of valid values. --or--offset or count is less than 0. |
ArgumentException | offset + count is greater than the length of buffer. |
InvalidOperationException | BeginXXX method used without providing an EndXXX event handler. |
Use the Udp.BeginSend method to send a datagram created from the data contained in buffer to the specified host asynchronously. When the data has been sent, the EndSend event is raised.
To synchronously send a datagram, use Send.
A UDP datagram provides little functionality over an IP datagram, adding a port number field which allows multiplexing on the receiving host and checksum field which provides basic error handling. Unlike TCP, UDP datagrams are sent as a unit. If Udp.BeginSend is called 3 times to send 3 datagrams to a host, the receiving host will have to call BeginReceive 3 times. Also, the size of each datagram sent will equal the size of each datagram received by the receiving host. In addition, since UDP is a connectionless protocol, any datagrams sent to the host are not guaranteed to be delivered. Therefore, any required error checking (outside of UDP's checksum implementation) will have to be done by the application-layer protocol.
To send a broadcast datagram, use "255.255.255.255" as the remote address. To sent a multicast datagram, use the multicast group address as the remote address after first joining a multicast group by using Udp.JoinMulitcastGroup.
The following example demonstrates sending data asynchronously.
[Visual Basic]
Private Sub AsynchTest()
' Begin listening for datagrams.
Udp1.Open(1111)
' Asynchronously send a datagram. EndSend event will be raised upon completion.
Dim buffer As Byte() = System.Text.Encoding.Default.GetBytes("test")
Udp1.BeginSend(buffer, "weezer", 8888)
End Sub
Private Sub Udp1_EndSend(ByVal sender As Object, ByVal e As DatagramEventArgs) Handles Udp1.EndSend
If e.Exception Is Nothing Then
Debug.WriteLine("Data sent: " + e.Datagram.ToString())
Else
Debug.WriteLine("Exception returned from event: " + e.Exception.ToString())
End If
End Sub
[C#]
private void AsynchTest()
{
// Begin listening for datagrams.
udp1.Open(1111);
// Asynchronously send a datagram. EndSend event will be raised upon completion.
byte[] buffer = System.Text.Encoding.Default.GetBytes("test");
udp1.BeginSend(buffer, "MyEchoServer", 7);
}
private void udp1_EndSend(object
sender, DatagramEventArgs e)
{
if(e.Exception == null)
{
Debug.WriteLine("Data sent: " + e.Datagram.ToString());
}
else
{
Debug.WriteLine("Exception returned from event: " + e.Exception.ToString());
}
}
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Udp Class | Udp Members | Overload List
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.